package com.briup.jz.web.controller;


import com.briup.jz.bean.Comment;
import com.briup.jz.bean.extend.CommentExtend;
import com.briup.jz.dao.CommentMapper;
import com.briup.jz.service.ICommentService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(description = "评论管理接口")
@RequestMapping("/comment")
@RestController
public class CommentController {

    @Autowired
    private ICommentService commentService;

    @ApiOperation(value = "查询全部")
    @GetMapping("findAll")
    public Message findAll(){
        List<Comment> list=commentService.finaAll();
        return MessageUtil.success(list);
    }
    @ApiOperation(value = "通过ID删除评论")
    @GetMapping("deletdById")
    public Message deletdById(long id){
       commentService.deleteById(id);
       return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "更新或者保存评论")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Comment comment){
        commentService.savaOrUpdate(comment);
        return MessageUtil.success("已保存");
    }

    @ApiOperation(value = "级联查询")
    @GetMapping("findAllWithChild")

    public Message findAllWithChild(){
        List<CommentExtend> list = commentService.findAllWithChild();
        return MessageUtil.success(list);

    }

}
